/*
 * EmployeePanel.java
 *
 * Created on __DATE__, __TIME__
 */

package com.popsGUI.java;

import java.text.DateFormat;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;

import com.popsDB.java.dto.Customers;
import com.popsDB.java.dto.CustomersPk;
import com.popsDB.java.dto.Employee;
import com.popsDB.java.dto.EmployeePk;
import com.popsDB.java.dto.Pricesheets;
import com.popsDB.java.dto.Positions;
import com.popsDB.java.dto.PositionsPk;

/**
 *
 * @author  __USER__
 */
public class EmployeePanel extends javax.swing.JPanel {

	/** Creates new form EmployeePanel */
	public EmployeePanel() {
		initComponents();
		com.popsGUI.java.notificationDialog notificationDialog = new com.popsGUI.java.notificationDialog(
				null, false);
	}

	//GEN-BEGIN:initComponents
	// <editor-fold defaultstate="collapsed" desc="Generated Code">
	private void initComponents() {

		selectEmployee_dialog = new javax.swing.JDialog();
		se_selectEmployee_combobox = new javax.swing.JComboBox();
		se_ok_button = new javax.swing.JButton();
		fieldsFail = new javax.swing.JDialog();
		OK = new javax.swing.JButton();
		message = new javax.swing.JLabel();
		message2 = new javax.swing.JLabel();
		custChangesSaved_dialog = new javax.swing.JDialog();
		ccs_label = new javax.swing.JLabel();
		ccs_ok_button = new javax.swing.JButton();
		permissionName = new javax.swing.JDialog();
		ep_permName_field = new javax.swing.JTextField();
		jLabel1 = new javax.swing.JLabel();
		perm_create_button = new javax.swing.JButton();
		ep_perm_panel1 = new javax.swing.JScrollPane();
		ep_permCreate_table = new javax.swing.JTable();
		ep_id_label = new javax.swing.JLabel();
		ep_id_field = new javax.swing.JLabel();
		ep_firstName_label = new javax.swing.JLabel();
		ep_firstName_field = new javax.swing.JTextField();
		ep_address_label = new javax.swing.JLabel();
		ep_address_field1 = new javax.swing.JTextField();
		ep_address_field2 = new javax.swing.JTextField();
		ep_city_label = new javax.swing.JLabel();
		ep_state_label = new javax.swing.JLabel();
		ep_city_field = new javax.swing.JTextField();
		ep_state_field = new javax.swing.JTextField();
		ep_zip_label = new javax.swing.JLabel();
		ep_zip_field = new javax.swing.JTextField();
		ep_phone_label = new javax.swing.JLabel();
		ep_phone_field = new javax.swing.JTextField();
		ep_cell_label = new javax.swing.JLabel();
		ep_cell_field = new javax.swing.JTextField();
		ep_status_label = new javax.swing.JLabel();
		ep_status_field = new javax.swing.JLabel();
		ep_driver_checkbox = new javax.swing.JCheckBox();
		ep_foreman_checkbox = new javax.swing.JCheckBox();
		ep_salesperson_checkbox = new javax.swing.JCheckBox();
		ep_extsalesperson_checkbox = new javax.swing.JCheckBox();
		ep_saveEmpChanges_button = new javax.swing.JButton();
		ep_empActivation_button = new javax.swing.JButton();
		ep_username_label = new javax.swing.JLabel();
		ep_password_label = new javax.swing.JLabel();
		ep_password_field = new javax.swing.JPasswordField();
		ep_username_field = new javax.swing.JTextField();
		ep_lastName_field = new javax.swing.JTextField();
		ep_lastName_label = new javax.swing.JLabel();
		ep_ssn_field = new javax.swing.JTextField();
		ep_ssn_label = new javax.swing.JLabel();
		ep_usernamePassword_button = new javax.swing.JButton();
		ep_selectEmployee_button = new javax.swing.JButton();
		ep_perm_panel = new javax.swing.JScrollPane();
		ep_perm_table = new javax.swing.JTable();
		ep_rights_field = new javax.swing.JLabel();
		ep_rights_combobox = new javax.swing.JComboBox();
		ep_createAccessRight_button = new javax.swing.JButton();

		selectEmployee_dialog.setMinimumSize(new java.awt.Dimension(370, 200));

		se_selectEmployee_combobox
				.setModel(new javax.swing.DefaultComboBoxModel(
						new String[] { "Select an employee..." }));

		se_ok_button.setText("OK");
		se_ok_button.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				se_ok_buttonActionPerformed(evt);
			}
		});

		javax.swing.GroupLayout selectEmployee_dialogLayout = new javax.swing.GroupLayout(
				selectEmployee_dialog.getContentPane());
		selectEmployee_dialog.getContentPane().setLayout(
				selectEmployee_dialogLayout);
		selectEmployee_dialogLayout
				.setHorizontalGroup(selectEmployee_dialogLayout
						.createParallelGroup(
								javax.swing.GroupLayout.Alignment.LEADING)
						.addGroup(
								selectEmployee_dialogLayout
										.createSequentialGroup()
										.addGroup(
												selectEmployee_dialogLayout
														.createParallelGroup(
																javax.swing.GroupLayout.Alignment.LEADING)
														.addGroup(
																selectEmployee_dialogLayout
																		.createSequentialGroup()
																		.addContainerGap()
																		.addComponent(
																				se_selectEmployee_combobox,
																				0,
																				306,
																				Short.MAX_VALUE))
														.addGroup(
																selectEmployee_dialogLayout
																		.createSequentialGroup()
																		.addGap(
																				137,
																				137,
																				137)
																		.addComponent(
																				se_ok_button)))
										.addContainerGap()));
		selectEmployee_dialogLayout
				.setVerticalGroup(selectEmployee_dialogLayout
						.createParallelGroup(
								javax.swing.GroupLayout.Alignment.LEADING)
						.addGroup(
								selectEmployee_dialogLayout
										.createSequentialGroup()
										.addGap(34, 34, 34)
										.addComponent(
												se_selectEmployee_combobox,
												javax.swing.GroupLayout.PREFERRED_SIZE,
												javax.swing.GroupLayout.DEFAULT_SIZE,
												javax.swing.GroupLayout.PREFERRED_SIZE)
										.addPreferredGap(
												javax.swing.LayoutStyle.ComponentPlacement.RELATED,
												67, Short.MAX_VALUE)
										.addComponent(se_ok_button)
										.addContainerGap()));

		fieldsFail.setMinimumSize(new java.awt.Dimension(350, 350));

		OK.setText("OK");
		OK.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				OKActionPerformed(evt);
			}
		});

		message.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
		message.setText("All fields are not entered correctly.");
		message.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);

		message2.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);

		javax.swing.GroupLayout fieldsFailLayout = new javax.swing.GroupLayout(
				fieldsFail.getContentPane());
		fieldsFail.getContentPane().setLayout(fieldsFailLayout);
		fieldsFailLayout
				.setHorizontalGroup(fieldsFailLayout
						.createParallelGroup(
								javax.swing.GroupLayout.Alignment.LEADING)
						.addGroup(
								fieldsFailLayout
										.createSequentialGroup()
										.addContainerGap()
										.addComponent(
												message,
												javax.swing.GroupLayout.DEFAULT_SIZE,
												330, Short.MAX_VALUE)
										.addContainerGap())
						.addGroup(
								fieldsFailLayout
										.createSequentialGroup()
										.addGap(100, 100, 100)
										.addComponent(
												OK,
												javax.swing.GroupLayout.DEFAULT_SIZE,
												147, Short.MAX_VALUE).addGap(
												103, 103, 103))
						.addGroup(
								fieldsFailLayout
										.createSequentialGroup()
										.addContainerGap()
										.addComponent(
												message2,
												javax.swing.GroupLayout.DEFAULT_SIZE,
												330, Short.MAX_VALUE)
										.addContainerGap()));
		fieldsFailLayout
				.setVerticalGroup(fieldsFailLayout
						.createParallelGroup(
								javax.swing.GroupLayout.Alignment.LEADING)
						.addGroup(
								fieldsFailLayout
										.createSequentialGroup()
										.addGap(21, 21, 21)
										.addComponent(message)
										.addGap(18, 18, 18)
										.addComponent(
												message2,
												javax.swing.GroupLayout.DEFAULT_SIZE,
												150, Short.MAX_VALUE)
										.addPreferredGap(
												javax.swing.LayoutStyle.ComponentPlacement.RELATED)
										.addComponent(OK).addContainerGap()));

		custChangesSaved_dialog
				.setMinimumSize(new java.awt.Dimension(300, 180));

		ccs_label.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
		ccs_label.setText("Customer changes have been saved!");

		ccs_ok_button.setText("OK");
		ccs_ok_button.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				ccs_ok_buttonActionPerformed(evt);
			}
		});

		javax.swing.GroupLayout custChangesSaved_dialogLayout = new javax.swing.GroupLayout(
				custChangesSaved_dialog.getContentPane());
		custChangesSaved_dialog.getContentPane().setLayout(
				custChangesSaved_dialogLayout);
		custChangesSaved_dialogLayout
				.setHorizontalGroup(custChangesSaved_dialogLayout
						.createParallelGroup(
								javax.swing.GroupLayout.Alignment.LEADING)
						.addGroup(
								custChangesSaved_dialogLayout
										.createSequentialGroup()
										.addGroup(
												custChangesSaved_dialogLayout
														.createParallelGroup(
																javax.swing.GroupLayout.Alignment.LEADING)
														.addGroup(
																custChangesSaved_dialogLayout
																		.createSequentialGroup()
																		.addGap(
																				128,
																				128,
																				128)
																		.addComponent(
																				ccs_ok_button))
														.addGroup(
																custChangesSaved_dialogLayout
																		.createSequentialGroup()
																		.addContainerGap()
																		.addComponent(
																				ccs_label,
																				javax.swing.GroupLayout.DEFAULT_SIZE,
																				276,
																				Short.MAX_VALUE)))
										.addContainerGap()));
		custChangesSaved_dialogLayout
				.setVerticalGroup(custChangesSaved_dialogLayout
						.createParallelGroup(
								javax.swing.GroupLayout.Alignment.LEADING)
						.addGroup(
								javax.swing.GroupLayout.Alignment.TRAILING,
								custChangesSaved_dialogLayout
										.createSequentialGroup()
										.addGap(42, 42, 42)
										.addComponent(ccs_label)
										.addPreferredGap(
												javax.swing.LayoutStyle.ComponentPlacement.RELATED,
												90, Short.MAX_VALUE)
										.addComponent(ccs_ok_button)
										.addContainerGap()));

		permissionName.setMinimumSize(new java.awt.Dimension(400, 400));

		jLabel1.setText("Enter Name for New Access Right Position");

		perm_create_button.setText("Save");
		perm_create_button
				.addActionListener(new java.awt.event.ActionListener() {
					public void actionPerformed(java.awt.event.ActionEvent evt) {
						perm_create_buttonActionPerformed(evt);
					}
				});

		ep_permCreate_table.setModel(new javax.swing.table.DefaultTableModel(
				new Object[][] { { "Create Order", new Boolean(true) },
						{ "View/Edit Order", new Boolean(true) },
						{ "Create Customer", new Boolean(true) },
						{ "View/Edit Customer", new Boolean(true) },
						{ "View Items", new Boolean(true) },
						{ "View/Edit Master Pricesheet", new Boolean(true) },
						{ "View/Edit Pricesheet", new Boolean(true) },
						{ "Create Employee", new Boolean(true) },
						{ "View/Edit Employee", new Boolean(true) },
						{ "Print Reports", new Boolean(true) } }, new String[] {
						"Access Rights", "Enabled" }) {
			Class[] types = new Class[] { java.lang.String.class,
					java.lang.Boolean.class };
			boolean[] canEdit = new boolean[] { false, true };

			public Class getColumnClass(int columnIndex) {
				return types[columnIndex];
			}

			public boolean isCellEditable(int rowIndex, int columnIndex) {
				return canEdit[columnIndex];
			}
		});
		ep_perm_panel1.setViewportView(ep_permCreate_table);

		javax.swing.GroupLayout permissionNameLayout = new javax.swing.GroupLayout(
				permissionName.getContentPane());
		permissionName.getContentPane().setLayout(permissionNameLayout);
		permissionNameLayout
				.setHorizontalGroup(permissionNameLayout
						.createParallelGroup(
								javax.swing.GroupLayout.Alignment.LEADING)
						.addGroup(
								permissionNameLayout
										.createSequentialGroup()
										.addGroup(
												permissionNameLayout
														.createParallelGroup(
																javax.swing.GroupLayout.Alignment.LEADING)
														.addGroup(
																permissionNameLayout
																		.createSequentialGroup()
																		.addGap(
																				159,
																				159,
																				159)
																		.addComponent(
																				perm_create_button))
														.addGroup(
																permissionNameLayout
																		.createSequentialGroup()
																		.addGap(
																				97,
																				97,
																				97)
																		.addGroup(
																				permissionNameLayout
																						.createParallelGroup(
																								javax.swing.GroupLayout.Alignment.LEADING)
																						.addComponent(
																								ep_permName_field,
																								javax.swing.GroupLayout.PREFERRED_SIZE,
																								192,
																								javax.swing.GroupLayout.PREFERRED_SIZE)
																						.addComponent(
																								jLabel1))))
										.addContainerGap(102, Short.MAX_VALUE))
						.addGroup(
								permissionNameLayout
										.createParallelGroup(
												javax.swing.GroupLayout.Alignment.LEADING)
										.addGroup(
												permissionNameLayout
														.createSequentialGroup()
														.addGap(27, 27, 27)
														.addComponent(
																ep_perm_panel1,
																javax.swing.GroupLayout.PREFERRED_SIZE,
																346,
																javax.swing.GroupLayout.PREFERRED_SIZE)
														.addContainerGap(27,
																Short.MAX_VALUE))));
		permissionNameLayout
				.setVerticalGroup(permissionNameLayout
						.createParallelGroup(
								javax.swing.GroupLayout.Alignment.LEADING)
						.addGroup(
								permissionNameLayout
										.createSequentialGroup()
										.addContainerGap()
										.addComponent(jLabel1)
										.addPreferredGap(
												javax.swing.LayoutStyle.ComponentPlacement.RELATED)
										.addComponent(
												ep_permName_field,
												javax.swing.GroupLayout.PREFERRED_SIZE,
												javax.swing.GroupLayout.DEFAULT_SIZE,
												javax.swing.GroupLayout.PREFERRED_SIZE)
										.addPreferredGap(
												javax.swing.LayoutStyle.ComponentPlacement.RELATED,
												215, Short.MAX_VALUE)
										.addComponent(perm_create_button)
										.addContainerGap())
						.addGroup(
								permissionNameLayout
										.createParallelGroup(
												javax.swing.GroupLayout.Alignment.LEADING)
										.addGroup(
												permissionNameLayout
														.createSequentialGroup()
														.addGap(58, 58, 58)
														.addComponent(
																ep_perm_panel1,
																javax.swing.GroupLayout.PREFERRED_SIZE,
																184,
																javax.swing.GroupLayout.PREFERRED_SIZE)
														.addContainerGap(58,
																Short.MAX_VALUE))));

		setPreferredSize(new java.awt.Dimension(1024, 679));

		ep_id_label.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
		ep_id_label.setText("Employee ID:");

		ep_id_field.setText("000000");

		ep_firstName_label
				.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
		ep_firstName_label.setText("First Name:");

		ep_address_label
				.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
		ep_address_label.setText("Address:");

		ep_city_label.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
		ep_city_label.setText("City:");

		ep_state_label.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
		ep_state_label.setText("State:");

		ep_zip_label.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
		ep_zip_label.setText("ZIP Code:");

		ep_phone_label.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
		ep_phone_label.setText("Phone Number:");

		ep_phone_field
				.setToolTipText("Please use the following format 123456789");

		ep_cell_label.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
		ep_cell_label.setText("Cell Phone:");

		ep_cell_field
				.setToolTipText("Please use the following format 123456789");

		ep_status_label
				.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
		ep_status_label.setText("Employee Status:");

		ep_status_field.setText("Active");

		ep_driver_checkbox.setText("Driver");

		ep_foreman_checkbox.setText("Foreman");

		ep_salesperson_checkbox.setText("Salesperson");

		ep_extsalesperson_checkbox.setText("External Salesperson");

		ep_saveEmpChanges_button.setText("Save Changes");
		ep_saveEmpChanges_button
				.addActionListener(new java.awt.event.ActionListener() {
					public void actionPerformed(java.awt.event.ActionEvent evt) {
						ep_saveEmpChanges_buttonActionPerformed(evt);
					}
				});

		ep_empActivation_button.setText("Deactivate Employee");
		ep_empActivation_button
				.addActionListener(new java.awt.event.ActionListener() {
					public void actionPerformed(java.awt.event.ActionEvent evt) {
						ep_empActivation_buttonActionPerformed(evt);
					}
				});

		ep_username_label.setText("Username:");

		ep_password_label.setText("Password:");

		ep_password_field
				.setToolTipText("Passwords should be between 8 and 18 characters and not begin with space");

		ep_lastName_label.setText("Last Name:");

		ep_ssn_field
				.setToolTipText("Please use the following format 123456789");

		ep_ssn_label.setText("SSN:");

		ep_usernamePassword_button.setMnemonic('p');
		ep_usernamePassword_button.setText("Username / Password");
		ep_usernamePassword_button
				.addActionListener(new java.awt.event.ActionListener() {
					public void actionPerformed(java.awt.event.ActionEvent evt) {
						ep_usernamePassword_buttonActionPerformed(evt);
					}
				});

		ep_selectEmployee_button.setText(". . .");
		ep_selectEmployee_button
				.addActionListener(new java.awt.event.ActionListener() {
					public void actionPerformed(java.awt.event.ActionEvent evt) {
						ep_selectEmployee_buttonActionPerformed(evt);
					}
				});

		ep_perm_table.setModel(new javax.swing.table.DefaultTableModel(
				new Object[][] { { "Create Order", null },
						{ "View/Edit Order", null },
						{ "Create Customer", null },
						{ "View/Edit Customer", null }, { "View Items", null },
						{ "View/Edit Master Pricesheet", null },
						{ "View/Edit Pricesheet", null },
						{ "Create Employee", null },
						{ "View/Edit Employee", null },
						{ "Print Reports", null } }, new String[] {
						"Access Rights", "Enabled" }) {
			Class[] types = new Class[] { java.lang.String.class,
					java.lang.Boolean.class };
			boolean[] canEdit = new boolean[] { false, false };

			public Class getColumnClass(int columnIndex) {
				return types[columnIndex];
			}

			public boolean isCellEditable(int rowIndex, int columnIndex) {
				return canEdit[columnIndex];
			}
		});
		ep_perm_panel.setViewportView(ep_perm_table);

		ep_rights_field.setText("Access Right Position: ");

		ep_rights_combobox.setModel(new javax.swing.DefaultComboBoxModel(
				new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
		ep_rights_combobox.addMouseListener(new java.awt.event.MouseAdapter() {
			public void mouseClicked(java.awt.event.MouseEvent evt) {
				ep_rights_comboboxMouseClicked(evt);
			}
		});
		ep_rights_combobox
				.addPopupMenuListener(new javax.swing.event.PopupMenuListener() {
					public void popupMenuCanceled(
							javax.swing.event.PopupMenuEvent evt) {
					}

					public void popupMenuWillBecomeInvisible(
							javax.swing.event.PopupMenuEvent evt) {
						ep_rights_comboboxPopupMenuWillBecomeInvisible(evt);
					}

					public void popupMenuWillBecomeVisible(
							javax.swing.event.PopupMenuEvent evt) {
					}
				});
		ep_rights_combobox
				.addActionListener(new java.awt.event.ActionListener() {
					public void actionPerformed(java.awt.event.ActionEvent evt) {
						ep_rights_comboboxActionPerformed(evt);
					}
				});
		ep_rights_combobox.addFocusListener(new java.awt.event.FocusAdapter() {
			public void focusGained(java.awt.event.FocusEvent evt) {
				ep_rights_comboboxFocusGained(evt);
			}
		});

		ep_createAccessRight_button.setText("Create New Access Right Position");
		ep_createAccessRight_button
				.addActionListener(new java.awt.event.ActionListener() {
					public void actionPerformed(java.awt.event.ActionEvent evt) {
						ep_createAccessRight_buttonActionPerformed(evt);
					}
				});

		javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
		this.setLayout(layout);
		layout
				.setHorizontalGroup(layout
						.createParallelGroup(
								javax.swing.GroupLayout.Alignment.LEADING)
						.addGroup(
								layout
										.createSequentialGroup()
										.addContainerGap()
										.addGroup(
												layout
														.createParallelGroup(
																javax.swing.GroupLayout.Alignment.TRAILING)
														.addGroup(
																layout
																		.createParallelGroup(
																				javax.swing.GroupLayout.Alignment.LEADING)
																		.addGroup(
																				layout
																						.createParallelGroup(
																								javax.swing.GroupLayout.Alignment.TRAILING)
																						.addComponent(
																								ep_lastName_label)
																						.addGroup(
																								layout
																										.createParallelGroup(
																												javax.swing.GroupLayout.Alignment.LEADING)
																										.addComponent(
																												ep_firstName_label)
																										.addComponent(
																												ep_status_label)
																										.addComponent(
																												ep_id_label)))
																		.addGroup(
																				layout
																						.createParallelGroup(
																								javax.swing.GroupLayout.Alignment.TRAILING,
																								false)
																						.addComponent(
																								ep_phone_label,
																								javax.swing.GroupLayout.DEFAULT_SIZE,
																								javax.swing.GroupLayout.DEFAULT_SIZE,
																								Short.MAX_VALUE)
																						.addComponent(
																								ep_cell_label,
																								javax.swing.GroupLayout.DEFAULT_SIZE,
																								javax.swing.GroupLayout.DEFAULT_SIZE,
																								Short.MAX_VALUE)
																						.addComponent(
																								ep_city_label)
																						.addComponent(
																								ep_state_label))
																		.addComponent(
																				ep_zip_label))
														.addComponent(
																ep_address_label)
														.addComponent(
																ep_ssn_label))
										.addPreferredGap(
												javax.swing.LayoutStyle.ComponentPlacement.RELATED)
										.addGroup(
												layout
														.createParallelGroup(
																javax.swing.GroupLayout.Alignment.LEADING)
														.addGroup(
																layout
																		.createSequentialGroup()
																		.addPreferredGap(
																				javax.swing.LayoutStyle.ComponentPlacement.RELATED)
																		.addGroup(
																				layout
																						.createParallelGroup(
																								javax.swing.GroupLayout.Alignment.LEADING,
																								false)
																						.addComponent(
																								ep_address_field2)
																						.addComponent(
																								ep_city_field)
																						.addComponent(
																								ep_state_field)
																						.addComponent(
																								ep_zip_field)
																						.addComponent(
																								ep_phone_field)
																						.addComponent(
																								ep_cell_field)
																						.addComponent(
																								ep_ssn_field)
																						.addComponent(
																								ep_driver_checkbox)
																						.addComponent(
																								ep_foreman_checkbox)
																						.addComponent(
																								ep_salesperson_checkbox)
																						.addComponent(
																								ep_extsalesperson_checkbox))
																		.addPreferredGap(
																				javax.swing.LayoutStyle.ComponentPlacement.RELATED,
																				113,
																				Short.MAX_VALUE)
																		.addGroup(
																				layout
																						.createParallelGroup(
																								javax.swing.GroupLayout.Alignment.LEADING)
																						.addGroup(
																								javax.swing.GroupLayout.Alignment.TRAILING,
																								layout
																										.createParallelGroup(
																												javax.swing.GroupLayout.Alignment.LEADING)
																										.addGroup(
																												layout
																														.createSequentialGroup()
																														.addComponent(
																																ep_rights_field)
																														.addPreferredGap(
																																javax.swing.LayoutStyle.ComponentPlacement.RELATED)
																														.addComponent(
																																ep_rights_combobox,
																																javax.swing.GroupLayout.PREFERRED_SIZE,
																																162,
																																javax.swing.GroupLayout.PREFERRED_SIZE))
																										.addComponent(
																												ep_perm_panel,
																												javax.swing.GroupLayout.PREFERRED_SIZE,
																												346,
																												javax.swing.GroupLayout.PREFERRED_SIZE))
																						.addGroup(
																								javax.swing.GroupLayout.Alignment.TRAILING,
																								layout
																										.createSequentialGroup()
																										.addComponent(
																												ep_createAccessRight_button)
																										.addGap(
																												79,
																												79,
																												79))))
														.addComponent(
																ep_address_field1,
																javax.swing.GroupLayout.PREFERRED_SIZE,
																javax.swing.GroupLayout.DEFAULT_SIZE,
																javax.swing.GroupLayout.PREFERRED_SIZE)
														.addComponent(
																ep_status_field)
														.addGroup(
																layout
																		.createSequentialGroup()
																		.addGroup(
																				layout
																						.createParallelGroup(
																								javax.swing.GroupLayout.Alignment.TRAILING)
																						.addGroup(
																								javax.swing.GroupLayout.Alignment.LEADING,
																								layout
																										.createSequentialGroup()
																										.addComponent(
																												ep_saveEmpChanges_button)
																										.addGap(
																												294,
																												294,
																												294)
																										.addComponent(
																												ep_empActivation_button))
																						.addGroup(
																								javax.swing.GroupLayout.Alignment.LEADING,
																								layout
																										.createSequentialGroup()
																										.addGroup(
																												layout
																														.createParallelGroup(
																																javax.swing.GroupLayout.Alignment.TRAILING,
																																false)
																														.addComponent(
																																ep_lastName_field)
																														.addComponent(
																																ep_firstName_field,
																																javax.swing.GroupLayout.DEFAULT_SIZE,
																																281,
																																Short.MAX_VALUE)
																														.addGroup(
																																javax.swing.GroupLayout.Alignment.LEADING,
																																layout
																																		.createSequentialGroup()
																																		.addComponent(
																																				ep_id_field)
																																		.addPreferredGap(
																																				javax.swing.LayoutStyle.ComponentPlacement.RELATED,
																																				javax.swing.GroupLayout.DEFAULT_SIZE,
																																				Short.MAX_VALUE)
																																		.addComponent(
																																				ep_selectEmployee_button)))
																										.addPreferredGap(
																												javax.swing.LayoutStyle.ComponentPlacement.RELATED,
																												207,
																												Short.MAX_VALUE)
																										.addGroup(
																												layout
																														.createParallelGroup(
																																javax.swing.GroupLayout.Alignment.LEADING)
																														.addComponent(
																																ep_username_label,
																																javax.swing.GroupLayout.Alignment.TRAILING)
																														.addComponent(
																																ep_password_label,
																																javax.swing.GroupLayout.Alignment.TRAILING))))
																		.addPreferredGap(
																				javax.swing.LayoutStyle.ComponentPlacement.RELATED)
																		.addGroup(
																				layout
																						.createParallelGroup(
																								javax.swing.GroupLayout.Alignment.LEADING,
																								false)
																						.addComponent(
																								ep_username_field)
																						.addComponent(
																								ep_password_field,
																								javax.swing.GroupLayout.DEFAULT_SIZE,
																								191,
																								Short.MAX_VALUE)
																						.addComponent(
																								ep_usernamePassword_button))))
										.addGap(643, 643, 643)));

		layout.linkSize(javax.swing.SwingConstants.HORIZONTAL,
				new java.awt.Component[] { ep_address_label, ep_cell_label,
						ep_city_label, ep_firstName_label, ep_id_label,
						ep_state_label, ep_status_label, ep_zip_label });

		layout.linkSize(javax.swing.SwingConstants.HORIZONTAL,
				new java.awt.Component[] { ep_address_field1,
						ep_address_field2, ep_cell_field, ep_city_field,
						ep_firstName_field, ep_phone_field, ep_state_field,
						ep_zip_field });

		layout
				.setVerticalGroup(layout
						.createParallelGroup(
								javax.swing.GroupLayout.Alignment.LEADING)
						.addGroup(
								layout
										.createSequentialGroup()
										.addGap(25, 25, 25)
										.addGroup(
												layout
														.createParallelGroup(
																javax.swing.GroupLayout.Alignment.BASELINE)
														.addComponent(
																ep_id_label)
														.addComponent(
																ep_id_field)
														.addComponent(
																ep_selectEmployee_button))
										.addPreferredGap(
												javax.swing.LayoutStyle.ComponentPlacement.RELATED)
										.addGroup(
												layout
														.createParallelGroup(
																javax.swing.GroupLayout.Alignment.BASELINE)
														.addComponent(
																ep_status_label)
														.addComponent(
																ep_status_field))
										.addPreferredGap(
												javax.swing.LayoutStyle.ComponentPlacement.RELATED)
										.addGroup(
												layout
														.createParallelGroup(
																javax.swing.GroupLayout.Alignment.BASELINE)
														.addComponent(
																ep_firstName_label)
														.addComponent(
																ep_firstName_field,
																javax.swing.GroupLayout.PREFERRED_SIZE,
																javax.swing.GroupLayout.DEFAULT_SIZE,
																javax.swing.GroupLayout.PREFERRED_SIZE)
														.addComponent(
																ep_username_label)
														.addComponent(
																ep_username_field,
																javax.swing.GroupLayout.PREFERRED_SIZE,
																javax.swing.GroupLayout.DEFAULT_SIZE,
																javax.swing.GroupLayout.PREFERRED_SIZE))
										.addPreferredGap(
												javax.swing.LayoutStyle.ComponentPlacement.RELATED)
										.addGroup(
												layout
														.createParallelGroup(
																javax.swing.GroupLayout.Alignment.BASELINE)
														.addComponent(
																ep_password_label)
														.addComponent(
																ep_password_field,
																javax.swing.GroupLayout.PREFERRED_SIZE,
																javax.swing.GroupLayout.DEFAULT_SIZE,
																javax.swing.GroupLayout.PREFERRED_SIZE)
														.addComponent(
																ep_lastName_field,
																javax.swing.GroupLayout.PREFERRED_SIZE,
																javax.swing.GroupLayout.DEFAULT_SIZE,
																javax.swing.GroupLayout.PREFERRED_SIZE)
														.addComponent(
																ep_lastName_label))
										.addPreferredGap(
												javax.swing.LayoutStyle.ComponentPlacement.RELATED)
										.addGroup(
												layout
														.createParallelGroup(
																javax.swing.GroupLayout.Alignment.LEADING)
														.addGroup(
																layout
																		.createSequentialGroup()
																		.addGroup(
																				layout
																						.createParallelGroup(
																								javax.swing.GroupLayout.Alignment.BASELINE)
																						.addComponent(
																								ep_address_field1,
																								javax.swing.GroupLayout.PREFERRED_SIZE,
																								javax.swing.GroupLayout.DEFAULT_SIZE,
																								javax.swing.GroupLayout.PREFERRED_SIZE)
																						.addComponent(
																								ep_address_label))
																		.addGap(
																				8,
																				8,
																				8)
																		.addComponent(
																				ep_address_field2,
																				javax.swing.GroupLayout.PREFERRED_SIZE,
																				javax.swing.GroupLayout.DEFAULT_SIZE,
																				javax.swing.GroupLayout.PREFERRED_SIZE)
																		.addPreferredGap(
																				javax.swing.LayoutStyle.ComponentPlacement.RELATED)
																		.addGroup(
																				layout
																						.createParallelGroup(
																								javax.swing.GroupLayout.Alignment.BASELINE)
																						.addComponent(
																								ep_city_label)
																						.addComponent(
																								ep_city_field,
																								javax.swing.GroupLayout.PREFERRED_SIZE,
																								javax.swing.GroupLayout.DEFAULT_SIZE,
																								javax.swing.GroupLayout.PREFERRED_SIZE))
																		.addPreferredGap(
																				javax.swing.LayoutStyle.ComponentPlacement.RELATED)
																		.addGroup(
																				layout
																						.createParallelGroup(
																								javax.swing.GroupLayout.Alignment.BASELINE)
																						.addComponent(
																								ep_state_label)
																						.addComponent(
																								ep_state_field,
																								javax.swing.GroupLayout.PREFERRED_SIZE,
																								javax.swing.GroupLayout.DEFAULT_SIZE,
																								javax.swing.GroupLayout.PREFERRED_SIZE))
																		.addPreferredGap(
																				javax.swing.LayoutStyle.ComponentPlacement.RELATED)
																		.addGroup(
																				layout
																						.createParallelGroup(
																								javax.swing.GroupLayout.Alignment.BASELINE)
																						.addComponent(
																								ep_zip_label)
																						.addComponent(
																								ep_zip_field,
																								javax.swing.GroupLayout.PREFERRED_SIZE,
																								javax.swing.GroupLayout.DEFAULT_SIZE,
																								javax.swing.GroupLayout.PREFERRED_SIZE))
																		.addPreferredGap(
																				javax.swing.LayoutStyle.ComponentPlacement.RELATED)
																		.addGroup(
																				layout
																						.createParallelGroup(
																								javax.swing.GroupLayout.Alignment.BASELINE)
																						.addComponent(
																								ep_phone_label)
																						.addComponent(
																								ep_phone_field,
																								javax.swing.GroupLayout.PREFERRED_SIZE,
																								javax.swing.GroupLayout.DEFAULT_SIZE,
																								javax.swing.GroupLayout.PREFERRED_SIZE))
																		.addPreferredGap(
																				javax.swing.LayoutStyle.ComponentPlacement.RELATED)
																		.addGroup(
																				layout
																						.createParallelGroup(
																								javax.swing.GroupLayout.Alignment.BASELINE)
																						.addComponent(
																								ep_cell_label)
																						.addComponent(
																								ep_cell_field,
																								javax.swing.GroupLayout.PREFERRED_SIZE,
																								javax.swing.GroupLayout.DEFAULT_SIZE,
																								javax.swing.GroupLayout.PREFERRED_SIZE))
																		.addPreferredGap(
																				javax.swing.LayoutStyle.ComponentPlacement.RELATED)
																		.addGroup(
																				layout
																						.createParallelGroup(
																								javax.swing.GroupLayout.Alignment.BASELINE)
																						.addComponent(
																								ep_ssn_field,
																								javax.swing.GroupLayout.PREFERRED_SIZE,
																								javax.swing.GroupLayout.DEFAULT_SIZE,
																								javax.swing.GroupLayout.PREFERRED_SIZE)
																						.addComponent(
																								ep_ssn_label))
																		.addGap(
																				18,
																				18,
																				18)
																		.addComponent(
																				ep_driver_checkbox)
																		.addPreferredGap(
																				javax.swing.LayoutStyle.ComponentPlacement.RELATED)
																		.addComponent(
																				ep_foreman_checkbox)
																		.addPreferredGap(
																				javax.swing.LayoutStyle.ComponentPlacement.RELATED)
																		.addComponent(
																				ep_salesperson_checkbox)
																		.addPreferredGap(
																				javax.swing.LayoutStyle.ComponentPlacement.RELATED)
																		.addComponent(
																				ep_extsalesperson_checkbox))
														.addGroup(
																layout
																		.createSequentialGroup()
																		.addComponent(
																				ep_usernamePassword_button)
																		.addGap(
																				30,
																				30,
																				30)
																		.addGroup(
																				layout
																						.createParallelGroup(
																								javax.swing.GroupLayout.Alignment.BASELINE)
																						.addComponent(
																								ep_rights_field)
																						.addComponent(
																								ep_rights_combobox,
																								javax.swing.GroupLayout.PREFERRED_SIZE,
																								javax.swing.GroupLayout.DEFAULT_SIZE,
																								javax.swing.GroupLayout.PREFERRED_SIZE))
																		.addGap(
																				9,
																				9,
																				9)
																		.addComponent(
																				ep_perm_panel,
																				javax.swing.GroupLayout.PREFERRED_SIZE,
																				184,
																				javax.swing.GroupLayout.PREFERRED_SIZE)
																		.addPreferredGap(
																				javax.swing.LayoutStyle.ComponentPlacement.RELATED)
																		.addComponent(
																				ep_createAccessRight_button)))
										.addPreferredGap(
												javax.swing.LayoutStyle.ComponentPlacement.RELATED,
												66, Short.MAX_VALUE)
										.addGroup(
												layout
														.createParallelGroup(
																javax.swing.GroupLayout.Alignment.BASELINE)
														.addComponent(
																ep_saveEmpChanges_button)
														.addComponent(
																ep_empActivation_button))
										.addGap(106, 106, 106)));
	}// </editor-fold>
	//GEN-END:initComponents

	private void ep_createAccessRight_buttonActionPerformed(
			java.awt.event.ActionEvent evt) {
		this.permissionName.setEnabled(true);
		this.permissionName.setVisible(true);
		this.permissionName.toFront();
	}

	private void ep_rights_comboboxPopupMenuWillBecomeInvisible(
			javax.swing.event.PopupMenuEvent evt) {
		if (!ep_rights_combobox.getSelectedItem().toString().equalsIgnoreCase(
				ACCESS_RIGHT)) {
			String name = ep_rights_combobox.getSelectedItem().toString();
			String rights = MEDIATOR.getAccessRights(name);
			System.out.println("ACCESSING: " + name + " with " + rights);
			this.populateAccessRights(rights);
		} else {
			String rights = "";
			for (int i = 0; i < ROW_NUMBERS; i++) {
				rights = rights.concat("0");
			}
			this.populateAccessRights(rights);
		}
	}

	private void ep_rights_comboboxActionPerformed(
			java.awt.event.ActionEvent evt) {
	}

	private void ep_rights_comboboxMouseClicked(java.awt.event.MouseEvent evt) {
	}

	private void ep_rights_comboboxFocusGained(java.awt.event.FocusEvent evt) {
	}

	private void perm_create_buttonActionPerformed(
			java.awt.event.ActionEvent evt) {
		String permission = "";

		for (int i = 0; i < ROW_NUMBERS; i++) {
			if ((Boolean) ep_permCreate_table.getValueAt(i, ENABLED_COLUMN) == false) {
				permission = permission.concat("0");
			} else {
				permission = permission.concat("1");
			}
		}

		String name = ep_permName_field.getText().toString();

		if (MEDIATOR.checkIfAccessRightNameExists(name)) {
			this.message.setText("Access Right Name Already Exists");
			this.message2.setText("");
			this.fieldsFail.setVisible(true);
			this.fieldsFail.toFront();
		} else {
			Positions pos = new Positions();
			pos.setName(name);
			pos.setPermissions(permission);

			MEDIATOR.insertPosition(pos);
			updateRightsCombobox();
			this.permissionName.setEnabled(false);
			this.permissionName.setVisible(false);
		}
	}

	private void ccs_ok_buttonActionPerformed(java.awt.event.ActionEvent evt) {
		custChangesSaved_dialog.setVisible(false);
	}

	private void OKActionPerformed(java.awt.event.ActionEvent evt) {
		this.fieldsFail.hide();
	}

	private void ep_selectEmployee_buttonActionPerformed(
			java.awt.event.ActionEvent evt) {
		//TODO: fix this code
		selectEmployee_dialog.setVisible(true);
		updateSelectEmployeeCombobox();
	}

	private void ep_usernamePassword_buttonActionPerformed(
			java.awt.event.ActionEvent evt) {
		// TODO add your handling code here:
	}

	void ep_empActivation_buttonActionPerformed(java.awt.event.ActionEvent evt) {
		if (ep_empActivation_button.getText().equals(ACTIVATE_EMPLOYEE)) {
			if (ep_id_field.getText().equals(EMPTY_EMPLOYEE_ID)) {
				this.message.setText("No Employee to Deactivate");
				this.message2.setText("");
				this.fieldsFail.setVisible(true);
				this.fieldsFail.toFront();
			} else {
				ep_empActivation_button.setText(DEACTIVATE_EMPLOYEE);
				ep_status_field.setText(ACTIVE);
			}

		} else {
			// Checks if there is actually an employee to deactivate.
			if (ep_id_field.getText().equals(EMPTY_EMPLOYEE_ID)) {
				this.message2.setText("");
				this.message.setText("No Employee to Deactivate");
				this.fieldsFail.setVisible(true);
				this.fieldsFail.toFront();
				// Checks if any customers are using the employee for anything.
			} else if (MEDIATOR.checkCustomerDependencies(Integer
					.parseInt(ep_id_field.getText()))) {
				ArrayList<String> failcode = MEDIATOR
						.getCustomerDependencies(Integer.parseInt(ep_id_field
								.getText()));
				if (failcode.size() > 0) {
					String error_str = "Employee can't be deactivated. These customers route their jobs to this employee:";
					String error_str2 = "<html><p style=\"text-align: center; color: red;\">";
					for (int i = 0; i < failcode.size(); i++) {
						error_str2 += failcode.get(i);
						if (i != failcode.size() - 1) {
							error_str2 += "<p style=\"text-align: center; color: red;\">";
						} else {
							error_str2 += "</p></html>";
						}
						System.out.println(failcode.get(i));
					}
					// Display the error box.
					System.out.println(error_str2);
					this.message.setText(error_str);
					this.message2.setText(error_str2);
					this.fieldsFail.setVisible(true);
					this.fieldsFail.toFront();
				}
			} else {

				ep_empActivation_button.setText(ACTIVATE_EMPLOYEE);
				ep_status_field.setText(INACTIVE);
				notificationDialog
						.displayNotification("To confirm deactivation please press SAVE button.");
			}
		}
	}

	void ep_saveEmpChanges_buttonActionPerformed(java.awt.event.ActionEvent evt) {
		ep_state_field.setText(ep_state_field.getText().toUpperCase());

		ArrayList<String> failcode = new ArrayList<String>();

		// Error checking the first name field.
		if (ep_firstName_field.getText().length() == 0
				|| ep_firstName_field.getText().substring(0).equals(" ")
				|| Character.toString(ep_firstName_field.getText().charAt(0))
						.equals(" ")) {
			failcode.add(ep_firstName_label.getText());
		}

		// Error checking the last name field.
		if (ep_lastName_field.getText().length() == 0
				|| ep_lastName_field.getText().substring(0).equals(" ")
				|| Character.toString(ep_lastName_field.getText().charAt(0))
						.equals(" ")) {
			failcode.add(ep_lastName_label.getText());
		}

		// Checking if the first and last name are unique before creating new employee.
		if (MEDIATOR.doesEmpLastNameExist(ep_lastName_field.getText())
				&& MEDIATOR.doesEmpFirstNameExist(ep_firstName_field.getText())) {
			if (MEDIATOR.checkIfUpdatingEmployee(Integer.parseInt(ep_id_field
					.getText().toString()), ep_firstName_field.getText()
					.toString(), ep_lastName_field.getText().toString()) == false) {
				failcode.add("Employee name already exists");
			}
		}

		// Error checking the address1 field.
		if (ep_address_field1.getText().length() == 0
				|| checkIfDouble(ep_address_field1.getText())
				|| Character.toString(ep_address_field1.getText().charAt(0))
						.equals(" ")) {
			failcode.add(ep_address_label.getText());
		}

		// Error checking the address2 field.
		if (ep_address_field2.getText().length() != 0
				&& checkIfDouble(ep_address_field2.getText())) {
			failcode.add(ep_address_label.getText());
		}

		// Error checking the city field.
		if (ep_city_field.getText().length() == 0
				|| checkIfDouble(ep_city_field.getText())
				|| Character.toString(ep_city_field.getText().charAt(0))
						.equals(" ")) {
			failcode.add(ep_city_label.getText());
		}

		// Error checking the state field.
		if (ep_state_field.getText().length() != 2
				|| checkStates(ep_state_field.getText()) == false
				|| Character.toString(ep_state_field.getText().charAt(0))
						.equals(" ")) {
			failcode.add(ep_state_label.getText());
		}

		// Error checking the zip field.
		if ((ep_zip_field.getText().length() != ZIP_LENGTH_MIN && ep_zip_field
				.getText().length() != ZIP_LENGTH_MAX)
				|| !checkIfDouble(ep_zip_field.getText())
				|| Character.toString(ep_zip_field.getText().charAt(0)).equals(
						" ")) {
			failcode.add(ep_zip_label.getText());
		}

		// Error checking the phone field.
		if ((ep_phone_field.getText().length() < PHONE_LENGTH_MIN || ep_phone_field
				.getText().length() > PHONE_LENGTH_MAX)
				|| !checkIfDouble(ep_phone_field.getText())
				|| Character.toString(ep_phone_field.getText().charAt(0))
						.equals(" ")) {
			failcode.add(ep_phone_label.getText());
		}

		// Error checking the cell field.
		if (ep_cell_field.getText().length() != 0
				&& (!checkIfDouble(ep_cell_field.getText()) || (ep_cell_field
						.getText().length() < PHONE_LENGTH_MIN || ep_cell_field
						.getText().length() > PHONE_LENGTH_MAX))) {
			failcode.add(ep_cell_label.getText());
		}

		// Error checking the SSN field.
		//|| MEDIATOR.checkEmployeeSSNUnique(ep_ssn_field.getText()) == false
		if ((ep_ssn_field.getText().length() != SSN_LENGTH)
				|| !checkIfDouble(ep_ssn_field.getText())
				|| Character.toString(ep_ssn_field.getText().charAt(0)).equals(
						" ")) {
			failcode.add(ep_ssn_label.getText());
		}

		// Checking if the SSN is unique
		if (!MEDIATOR.checkEmployeeSSNUnique(ep_ssn_field.getText().toString(),
				Integer.parseInt(ep_id_field.getText()))) {
			failcode.add("SSN already exists. Please enter a different one.");
		}

		// Error checking the position checkboxes
		if (ep_foreman_checkbox.isSelected() == false
				&& ep_salesperson_checkbox.isSelected() == false
				&& ep_driver_checkbox.isSelected() == false
				&& ep_extsalesperson_checkbox.isSelected() == false) {
			failcode.add("Employee Position:");
		}

		// Error checking the username.
		//|| MEDIATOR.checkEmployeeUsernameUnique(ep_username_field.getText()) == false
		if (ep_username_field.getText().length() == 0
				|| ep_username_field.getText().substring(0).equals(" ")
				|| Character.toString(ep_username_field.getText().charAt(0))
						.equals(" ")) {
			failcode.add(ep_username_label.getText());
		}

		// Check if username is unique
		if (!MEDIATOR.checkEmployeeUsernameUnique(ep_username_field.getText()
				.toString(), Integer.parseInt(ep_id_field.getText()))) {
			failcode.add("Username already exists. Please select another.");
		}

		// Error checking the password field.
		if (ep_password_field.getText().length() == 0
				|| ep_password_field.getText().substring(0).equals(" ")
				|| Character.toString(ep_password_field.getText().charAt(0))
						.equals(" ")
				|| ep_password_field.getText().length() < PASSWORD_MIN
				|| ep_password_field.getText().length() > PASSWORD_MAX) {
			failcode.add(ep_password_label.getText());
		}

		// Error checking the Access Rights combobox
		if (ep_rights_combobox.getSelectedItem().toString().equalsIgnoreCase(
				ACCESS_RIGHT)) {
			failcode.add(ep_rights_field.getText());
		}

		//TODO: Add employee permissions table here.
		String permission = "";

		for (int i = 0; i < ROW_NUMBERS; i++) {
			if ((Boolean) ep_perm_table.getValueAt(i, ENABLED_COLUMN) == null) {
				permission = permission.concat("0");
			} else {
				permission = permission.concat("1");
			}
		}

		System.out.println("PERMISSION: " + permission);

		String permName = "";

		if (MEDIATOR.checkIfPermissionExists(permission)) {
			permName = MEDIATOR.getPermissionName(permission);
		}

		// If there are any errors in the failcode array, report the errors to the user.
		if (failcode.size() > 0) {
			String error_str = "Please fill out the following fields to complete the form:";
			String error_str2 = "<html><p style=\"text-align: center; color: red;\">";
			for (int i = 0; i < failcode.size(); i++) {
				error_str2 += failcode.get(i);
				if (i != failcode.size() - 1) {
					error_str2 += "<p style=\"text-align: center; color: red;\">";
				} else {
					error_str2 += "</p></html>";
				}
				System.out.println(failcode.get(i));
			}
			// Display the error box.
			System.out.println(error_str2);
			this.message.setText(error_str);
			this.message2.setText(error_str2);
			this.fieldsFail.setVisible(true);
			this.fieldsFail.toFront();
		}

		// Else create an employee object to be passed into the DAO.
		else {
			ep_state_field.setText(ep_state_field.getText().toUpperCase());

			Employee emp = getEmployeeInfo();
			EmployeePk empPk = getEmployeePk();

			// If the customer already exists, edit the customer.
			if (!ep_id_field.getText().equals(EMPTY_EMPLOYEE_ID)) {
				emp.setEmployeeID(Integer.parseInt(ep_id_field.getText()));
				empPk.setEmployeeID(Integer.parseInt(ep_id_field.getText()));
				MEDIATOR.updateEmployee(empPk, emp);
				ccs_label.setText("Employee changes have been saved!");
				custChangesSaved_dialog.setVisible(true);
			}
			// Else create a new customer in the database with a unique id.
			else {
				int id = MEDIATOR.employeeAutoIncrement();
				emp.setEmployeeID(id);
				MEDIATOR.insertEmployee(emp);
				ep_id_field.setText("" + id);
				ccs_label.setText("Employee has been created!");
				custChangesSaved_dialog.setVisible(true);
			}
		}

	}

	private void se_ok_buttonActionPerformed(java.awt.event.ActionEvent evt) {
		int EmpID = MEDIATOR.getEmployeeID((String) se_selectEmployee_combobox
				.getSelectedItem());
		if (EmpID == -1) {
			// TODO: Add error pop up menu.
		} else {
			setRights();
			ep_id_field.setText(Integer.toString(EmpID));
			selectEmployee_dialog.setVisible(false);
			fill_Employee_Screen();
		}
	}

	//GEN-BEGIN:variables
	// Variables declaration - do not modify
	private javax.swing.JButton OK;
	private javax.swing.JLabel ccs_label;
	private javax.swing.JButton ccs_ok_button;
	private javax.swing.JDialog custChangesSaved_dialog;
	private javax.swing.JTextField ep_address_field1;
	private javax.swing.JTextField ep_address_field2;
	private javax.swing.JLabel ep_address_label;
	private javax.swing.JTextField ep_cell_field;
	private javax.swing.JLabel ep_cell_label;
	private javax.swing.JTextField ep_city_field;
	private javax.swing.JLabel ep_city_label;
	private javax.swing.JButton ep_createAccessRight_button;
	private javax.swing.JCheckBox ep_driver_checkbox;
	private javax.swing.JButton ep_empActivation_button;
	private javax.swing.JCheckBox ep_extsalesperson_checkbox;
	private javax.swing.JTextField ep_firstName_field;
	private javax.swing.JLabel ep_firstName_label;
	private javax.swing.JCheckBox ep_foreman_checkbox;
	private javax.swing.JLabel ep_id_field;
	private javax.swing.JLabel ep_id_label;
	private javax.swing.JTextField ep_lastName_field;
	private javax.swing.JLabel ep_lastName_label;
	private javax.swing.JPasswordField ep_password_field;
	private javax.swing.JLabel ep_password_label;
	private javax.swing.JTable ep_permCreate_table;
	private javax.swing.JTextField ep_permName_field;
	private javax.swing.JScrollPane ep_perm_panel;
	private javax.swing.JScrollPane ep_perm_panel1;
	private javax.swing.JTable ep_perm_table;
	private javax.swing.JTextField ep_phone_field;
	private javax.swing.JLabel ep_phone_label;
	private javax.swing.JComboBox ep_rights_combobox;
	private javax.swing.JLabel ep_rights_field;
	private javax.swing.JCheckBox ep_salesperson_checkbox;
	private javax.swing.JButton ep_saveEmpChanges_button;
	public javax.swing.JButton ep_selectEmployee_button;
	private javax.swing.JTextField ep_ssn_field;
	private javax.swing.JLabel ep_ssn_label;
	private javax.swing.JTextField ep_state_field;
	private javax.swing.JLabel ep_state_label;
	private javax.swing.JLabel ep_status_field;
	private javax.swing.JLabel ep_status_label;
	private javax.swing.JButton ep_usernamePassword_button;
	private javax.swing.JTextField ep_username_field;
	private javax.swing.JLabel ep_username_label;
	private javax.swing.JTextField ep_zip_field;
	private javax.swing.JLabel ep_zip_label;
	private javax.swing.JDialog fieldsFail;
	private javax.swing.JLabel jLabel1;
	private javax.swing.JLabel message;
	private javax.swing.JLabel message2;
	private javax.swing.JButton perm_create_button;
	private javax.swing.JDialog permissionName;
	private javax.swing.JButton se_ok_button;
	private javax.swing.JComboBox se_selectEmployee_combobox;
	private javax.swing.JDialog selectEmployee_dialog;
	// End of variables declaration//GEN-END:variables
	private com.popsGUI.java.notificationDialog notificationDialog;
	//TODO: the start of our code
	////////////////Our variable declarations /////////////////
	//TODO: clean out unnecessary variables out of here
	//CustomersDao CustomersDAO = CustomersDaoFactory.create();
	//	ItemsDao ItemsDAO = ItemsDaoFactory.create();
	//	OrdereditemsDao OrdereditemsDAO = OrdereditemsDaoFactory.create();
	//	OrdersDao OrdersDAO = OrdersDaoFactory.create();

	Mediator MEDIATOR = Mediator.getInstance();

	DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm");
	DecimalFormat decimalPriceFormat = new DecimalFormat("#.##");

	final String ACTIVE = "Active";
	final String INACTIVE = "Inactive";
	final String ACTIVATE_EMPLOYEE = "Activate Employee";
	final String DEACTIVATE_EMPLOYEE = "Deactivate Employee";
	final String ACCESS_RIGHT = "Select an access right...";
	final String EMPTY_EMPLOYEE_ID = "00000";
	final String PHONE_EXAMPLE = "e.g. 1234567890";
	final String SSN_EXAMPLE = "e.g. 333224444";
	
	final int ZIP_LENGTH_MIN = 5;
	final int ZIP_LENGTH_MAX = 10;
	final int PHONE_LENGTH_MIN = 7;
	final int PHONE_LENGTH_MAX = 10;
	final int SSN_LENGTH = 9;
	final int PASSWORD_MIN = 5;
	final int PASSWORD_MAX = 18;

	final int PERMISSION_COLUMN = 0;
	final int ENABLED_COLUMN = 1;
	final int ROW_NUMBERS = 10;

	///////////// End of our variable declarations /////////////

	// Show the selectEmployee_dialog
	public void showSelectEmployeeDialog(boolean visible) {
		selectEmployee_dialog.setVisible(visible);
	}

	// Updates the select employee combobox in the select employee dialog
	public void updateSelectEmployeeCombobox() {
		// se_selectEmployee_combobox
		// Clears the combobox
		se_selectEmployee_combobox.removeAllItems();
		// Adds 'Select a customer...' to the top of the list
		se_selectEmployee_combobox.addItem("Select an employee...");
		// Adds all the customers to the list
		String[] newEmpList = MEDIATOR.getEmployeeNames();
		for (int i = 0; i < newEmpList.length; i++) {
			se_selectEmployee_combobox.addItem(newEmpList[i]);
		}
	}

	// Updates the permissions combobox 
	public void updateRightsCombobox() {
		// Clears the combobox
		ep_rights_combobox.removeAllItems();
		// Adds 'Select an access right...' to the top of the list
		ep_rights_combobox.addItem(ACCESS_RIGHT);
		// Adds all the access rights to the list
		Positions[] pos = MEDIATOR.getPositions();
		for (int i = 0; i < pos.length; i++) {
			ep_rights_combobox.addItem(pos[i].getName());
		}
	}

	private boolean checkIfDouble(String text) {
		// Checking if the text contains any letters.
		try {
			Double.parseDouble(text);
		} catch (NumberFormatException nfe) {
			return false;
		}
		return true;
	}

	private boolean checkStates(String state) {
		String[] states = { "AL", "AK", "AZ", "AR", "CA", "CO", "CT", "DE",
				"FL", "GA", "HI", "ID", "IL", "IN", "IA", "KS", "KY", "LA",
				"ME", "MD", "MA", "MI", "MN", "MS", "MO", "MT", "NE", "NV",
				"NH", "NJ", "NM", "NY", "NC", "ND", "OH", "OK", "OR", "PA",
				"RI", "SC", "SD", "TN", "TX", "UT", "VT", "VA", "WA", "WV",
				"WI", "WY" };
		for (int i = 0; i < states.length; i++) {
			if (state.equals(states[i])) {
				return true;
			}
		}
		return false;
	}

	private void populateAccessRights(String rights) {
		if (rights.length() == ROW_NUMBERS) {
			for (int i = 0; i < ROW_NUMBERS; i++) {
				if (rights.charAt(i) == '0') {
					ep_perm_table.setValueAt(false, i, ENABLED_COLUMN);
				} else {
					ep_perm_table.setValueAt(true, i, ENABLED_COLUMN);
				}
			}
		}
	}

	private EmployeePk getEmployeePk() {
		EmployeePk empPk = new EmployeePk();
		int EmpID = Integer.parseInt(ep_id_field.getText());
		empPk.setEmployeeID(EmpID);
		return empPk;
	}

	private Employee getEmployeeInfo() {
		Employee emp = new Employee();

		emp.setFirstName(ep_firstName_field.getText());
		emp.setLastName(ep_lastName_field.getText());
		emp.setAddress(ep_address_field1.getText());
		emp.setAddress2(ep_address_field2.getText());
		emp.setCity(ep_city_field.getText());
		emp.setState(ep_state_field.getText());
		emp.setZip(ep_zip_field.getText());
		emp.setPhoneNumber(ep_phone_field.getText());
		emp.setCellNumber(ep_cell_field.getText());
		emp.setSsn(ep_ssn_field.getText());
		emp.setUsername(ep_username_field.getText());
		emp.setPassword(ep_password_field.getText());
		if ((ep_status_field.getText()).equals(ACTIVE)) {
			System.out.println("Employee status set to 1.");
			emp.setIsActive((short) 1);
		} else if (ep_status_field.getText().equals(INACTIVE)) {
			System.out.println("Employee status set to 0;");
			emp.setIsActive((short) 0);
		} else {
			System.out.println("Employee status was not set.");
		}

		//TODO: fix to use the new employee table
		if (ep_driver_checkbox.isSelected() == true) {
			emp.setIsDriver((short) 1);
		} else {
			emp.setIsDriver((short) 0);
		}

		if (ep_foreman_checkbox.isSelected() == true) {
			emp.setIsForeman((short) 1);
		} else {
			emp.setIsForeman((short) 0);
		}

		if (ep_salesperson_checkbox.isSelected() == true) {
			emp.setIsSalesman((short) 1);
		} else {
			emp.setIsSalesman((short) 0);
		}

		if (ep_extsalesperson_checkbox.isSelected() == true) {
			emp.setIsExtSalesman((short) 1);
		} else {
			emp.setIsExtSalesman((short) 0);
		}

		// Gets the Position ID
		Positions[] pos = MEDIATOR.getPositions();
		for (int i = 0; i < pos.length; i++) {
			if (ep_rights_combobox.getSelectedItem().toString().equals(
					pos[i].getName().toString())) {
				emp.setPositionID(pos[i].getPositionID());
			}
		}

		//		emp.setPositionID(MEDIATOR.getPositionID(this.ep_rights_combobox
		//				.getSelectedItem().toString()));

		return emp;
	}

	// Sets all the interactive components enabled/disabled
	public void setEmployeePanelComponentsEnabledParameterTo(boolean flag) {
		this.setEnabled(flag);
		//this.ep_selectEmployee_button.setEnabled(flag);

		this.ep_empActivation_button.setEnabled(flag);
		this.ep_saveEmpChanges_button.setEnabled(flag);
		this.ep_usernamePassword_button.setEnabled(flag);
		this.ep_driver_checkbox.setEnabled(flag);
		this.ep_foreman_checkbox.setEnabled(flag);
		this.ep_salesperson_checkbox.setEnabled(flag);
		this.ep_extsalesperson_checkbox.setEnabled(flag);
		
		if (flag) {
			this.ep_phone_label.setToolTipText(PHONE_EXAMPLE);
			this.ep_phone_field.setToolTipText(PHONE_EXAMPLE);
			this.ep_cell_label.setToolTipText(PHONE_EXAMPLE);
			this.ep_cell_field.setToolTipText(PHONE_EXAMPLE);
			this.ep_ssn_label.setToolTipText(SSN_EXAMPLE);
			this.ep_ssn_field.setToolTipText(SSN_EXAMPLE);
		}
		else {
			this.ep_phone_label.setToolTipText(null);
			this.ep_phone_field.setToolTipText(null);
			this.ep_cell_label.setToolTipText(null);
			this.ep_cell_field.setToolTipText(null);
			this.ep_ssn_label.setToolTipText(null);
			this.ep_ssn_field.setToolTipText(null);
		}
	}

	// Sets up the screen so you can create an employee
	public void setNewEmployee() {
		ep_id_field.setText(EMPTY_EMPLOYEE_ID);
		ep_firstName_field.setText("");
		ep_lastName_field.setText("");
		ep_status_field.setText(ACTIVE);
		ep_empActivation_button.setText(DEACTIVATE_EMPLOYEE);
		ep_address_field1.setText("");
		ep_address_field2.setText("");
		ep_city_field.setText("");
		ep_state_field.setText("");
		ep_zip_field.setText("");
		ep_phone_field.setText("");
		ep_cell_field.setText("");
		ep_ssn_field.setText("");
		ep_username_field.setText("");
		ep_password_field.setText("");

		ep_foreman_checkbox.setSelected(false);
		ep_salesperson_checkbox.setSelected(false);
		ep_extsalesperson_checkbox.setSelected(false);
		ep_driver_checkbox.setSelected(false);
		updateRightsCombobox();
		setRights();

		this.setUnusedEmployeeFieldsInvisible();
	}

	public void fill_Employee_Screen() {

		// Getting the customer index from the screen.
		String aString = ep_id_field.getText();
		int EmpID = Integer.parseInt(aString);

		if (EmpID == popsGUIMainMenu.userID) {
			ep_username_field.setEnabled(true);
			ep_password_field.setEnabled(true);
		}

		// custIndex = the customer's index in the Customers array in the mediator
		int empIndex = MEDIATOR.getEmployeeListNumber(EmpID);

		// Checks whether the given employee is active based on its empIndex.
		if (MEDIATOR.getEmployeeIsActive(empIndex)) {
			ep_status_field.setText(ACTIVE);
			ep_empActivation_button.setText(DEACTIVATE_EMPLOYEE);
		} else {
			ep_status_field.setText(INACTIVE);
			ep_empActivation_button.setText(ACTIVATE_EMPLOYEE);
		}

		// Sets all fields of the employee screen
		ep_firstName_field.setText(MEDIATOR.getEmployeeFirstName(empIndex));
		ep_lastName_field.setText(MEDIATOR.getEmployeeLastName(empIndex));
		ep_address_field1.setText(MEDIATOR.getEmployeeAddress1(empIndex));
		ep_address_field2.setText(MEDIATOR.getEmployeeAddress2(empIndex));
		ep_city_field.setText(MEDIATOR.getEmployeeCity(empIndex));
		ep_state_field.setText(MEDIATOR.getEmployeeState(empIndex));
		ep_zip_field.setText(MEDIATOR.getEmployeeZip(empIndex));
		ep_phone_field.setText(MEDIATOR.getEmployeePhoneNumber(empIndex));
		ep_cell_field.setText(MEDIATOR.getEmployeeCellNumber(empIndex));
		ep_ssn_field.setText(MEDIATOR.getEmployeeSSN(empIndex));
		ep_username_field.setText(MEDIATOR.getUsername(empIndex));
		ep_password_field.setText(MEDIATOR.getPassword(empIndex));
		ep_driver_checkbox.setSelected(MEDIATOR.getEmployeeIsDriver(empIndex));
		ep_foreman_checkbox
				.setSelected(MEDIATOR.getEmployeeIsForeman(empIndex));
		ep_salesperson_checkbox.setSelected(MEDIATOR
				.getEmployeeIsSalesperson(empIndex));
		ep_extsalesperson_checkbox.setSelected(MEDIATOR
				.getEmployeeIsExternalSalesperson(empIndex));

		Positions[] newPositions = MEDIATOR.getPositions();
		String name = MEDIATOR.getAccessRights(empIndex);
		String rights = "";
		for (int i = 0; i < newPositions.length; i++) {
			if (name.equals(newPositions[i].getName().toString())) {
				rights = newPositions[i].getPermissions();
				ep_rights_combobox.setSelectedIndex(++i);
			}
		}
		if (rights != "") {
			this.populateAccessRights(rights);
		}

	}

	public void setRights() {
		if (popsGUIMainMenu.userID == 1) {
			ep_username_field.setEnabled(true);
			ep_password_field.setEnabled(true);
		} else {
			ep_username_field.setEnabled(false);
			ep_password_field.setEnabled(false);
		}
	}

	public void setUnusedEmployeeFieldsInvisible() {
		// Setting unused Employee fields to invisible.
		ep_usernamePassword_button.setVisible(false);

	}

}